// JavaScript Document
$(
	function(){
		$(".p2_sortul li").click(function(){
			$(this).attr('class','p2_sortli02');
			$(this).siblings().attr('class','p2_sortli01');
			$('#metadata_'+$(this).attr('parentid')).val($(this).attr('selfid'));
			formatFormData();
		});
//		$('#sortby_price_select').change(function(){formatFormData()});
//		$('#sortby_created_select').change(function(){formatFormData()});
	}
);

function formatFormData(int_page){
    var str_filter = '/' + $('#categoryid').val();
    if(int_page)
        str_filter += '/page/' + int_page;
    //获取filter
    $("#sortForm li[class='p2_sortli02'][selfid!='0']").each(function(){
        str_filter += '/' + this.getAttribute('parentid') + '/' + this.getAttribute('selfid');
    });
    //获取sort
    if($('#sortby_price_select').get()[0]){
        if($('#sortby_price_select').val()!='0'){
            str_filter += '/price/' + $('#sortby_price_select').val();
        }else if($('#sortby_created_select').val()!='0'){
            str_filter += '/created/' + $('#sortby_created_select').val();
        }
    }
    $.ajax({
        type: 'post',
        url: '/a/categorysearch'+str_filter,
        dataType: "html",
        async: false,  //false is synchronization , true is asynchronism
        success: function(data){
            $('#searchResultBlock').replaceWith(data);
            window.location='#searchresultplace';
            return true;
        },
        error: function(){
            result = false;
        }
    });
}
